package top.weiliang.springboot3.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.weiliang.springboot3.base.PageBean;
import top.weiliang.springboot3.base.R;
import top.weiliang.springboot3.entity.TbClass;
import top.weiliang.springboot3.service.TbClassService;
import top.weiliang.springboot3.vo.PageVO;

import java.util.List;

@RestController
@RequestMapping("/class")
@RequiredArgsConstructor
public class TbClassController {
    private final TbClassService tbClassService;

    @GetMapping("/queryAll")
    public R<PageVO<TbClass>> queryAll(PageBean pageBean,TbClass tbClass){
        return tbClassService.queryPage(pageBean,tbClass);
    }

    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbClass>> queryPage(@PathVariable("pn")Long pageNumber,@PathVariable("ps") Long pageSize, TbClass tbClass){
        return tbClassService.queryPage(PageBean.instance(pageNumber,pageSize) ,tbClass);
    }


//    @PostMapping表示必须使用post请求，@RequestBody表示接收json格式的参数提交
    @PostMapping("")
    @ResponseBody
    public R<String> insert(@RequestBody TbClass tbClass){
        return tbClassService.insert(tbClass);
    }

    @GetMapping
    public R<List<TbClass>>query(TbClass tbClass){

        return tbClassService.query(tbClass);
    }

//    @PathVariable表示路径参数
    @GetMapping("/{id}")
    public R<TbClass>queryById(@PathVariable("id") Integer id){

        return tbClassService.queryById(id);
    }

    //修改必须是PutMapping
    @PutMapping("")
    public R<String> update(@RequestBody TbClass tbClass){
        return tbClassService.update(tbClass);
    }

    //删除必须是DeleteMapping
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id){
        return tbClassService.delete(id);
    }

}
